package com.github.zhengchalei;

import com.github.zhengchalei.domain.Order;
import com.github.zhengchalei.mapper.OrderRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.Arrays;
import java.util.List;

/**
 * springboot sharding sphere jdbc应用程序
 *
 * @author stone
 * @date 2022/02/20
 */
@Slf4j
@SpringBootApplication
public class SpringbootShardingSphereJdbcApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootShardingSphereJdbcApplication.class, args);
    }


    @Bean
    public CommandLineRunner commandLineRunner(OrderRepository orderRepository) {
        return args -> {
//            for (int i = 0; i < 500; i++) {
//                SnowflakeKeyGenerateAlgorithm snowflakeKeyGenerateAlgorithm = new SnowflakeKeyGenerateAlgorithm();
//                snowflakeKeyGenerateAlgorithm.init();
//                Order build = Order.builder().id((Long) snowflakeKeyGenerateAlgorithm.generateKey()).name("xiaoshitou" + i).build();
//                orderRepository.saveAndFlush(build);
//            }
            // Actual SQL: ds ::: select order0_.id as id1_0_0_, order0_.name as name2_0_0_ from t_order_2 order0_ where order0_.id=? ::: [702373341788372992]
//            log.info("find_by_id: {}", orderRepository.findById(702373341788372992L).get());
            List<Order> data = orderRepository.findAllById(Arrays.asList(702373340769157120L, 702373341788372992L));
            log.info("data: {}", data);
        };
    }
}
